// <copyright file="BlogContextInit.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Blog.Data
{
    using Blog.Data.Entities;
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;

    public class BlogContextInit : DropCreateDatabaseIfModelChanges<BlogDataContext>
    {
        protected override void Seed(BlogDataContext context)
        {
            #region Blog Categories

            var category1 = new BlogEntryCategory() { Alias = "main", CategoryName = "Main", Picture = "smile", SortOrder = 0, IsActive = true };
            context.BlogEntryCategories.Add(category1);

            var category2 = new BlogEntryCategory() { Alias = "public", CategoryName = "Public", Picture = "group", SortOrder = 2, IsActive = true };
            context.BlogEntryCategories.Add(category2);

            var category3 = new BlogEntryCategory() { Alias = "news", CategoryName = "News", Picture = "rss", SortOrder = 1, IsActive = true };
            context.BlogEntryCategories.Add(category3);
            context.SaveChanges();

            #endregion

            #region Posts
            var cts = context.BlogEntryCategories.ToList();
           
            context.BlogEntries.Add(new BlogEntry
            {
                Created = new DateTime(DateTime.Today.Year, (DateTime.Now.Month - 1 <= 0 ? DateTime.Now.Month + 1 : DateTime.Now.Month - 1), DateTime.Today.Day), 
                CategoryId = cts[0].Id, 
                Header = "Some Really Cool Information",
                HeaderUrl = "some-really-cool-info", 
                ShortContent = @"<p><img alt='' src='/Uploads//MyFolder/blog/blog-thumb-2.jpg' style='width: 120px; height: 119px; border-width: 2px; border-style: solid; margin: 5px 10px; float: left;' />Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus dapibus nisl sit amet imperdiet. In hac habitasse platea dictumst. 
                                Suspendisse gravida ante nisi, sit amet volutpat augue aliquam non. Nulla sit amet velit faucibus, consectetur magna eu, feugiat augue. Maecenas in consequat lacus. 
                                Nulla placerat risus risus, mattis volutpat nisi accumsan at. Morbi imperdiet ultrices nunc sed consequat. Morbi blandit nisi nisi, ut aliquam orci posuere non. In hac habitasse platea dictumst. In eros risus, sodales quis luctus sed, sagittis quis mauris. Maecenas a felis enim. Etiam ac tempus justo.Pellentesque tincidunt posuere pretium. 
                                Integer eu augue sem. Pellentesque eget metus at nisi mattis elementum. Nunc erat sapien, eleifend quis est ut, pretium mattis nunc. Fusce vitae accumsan risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus bibendum risus dui, vitae fermentum magna imperdiet quis. Donec ornare ipsum quis nibh vestibulum, 
                                nec dignissim dolor egestas. Nunc rutrum condimentum egestas. Etiam porta congue lectus eu facilisis.</p>
                ",
                Content = @"<p><img alt='' src='/Uploads//MyFolder/blog/blog2-big.jpg' style='width: 764px; height: 287px; border-width: 2px; border-style: solid;' /></p>
                            <p style='text-align: justify;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus dapibus nisl sit amet imperdiet. In hac habitasse platea dictumst. Suspendisse gravida ante nisi, sit amet volutpat augue aliquam non. Nulla sit amet velit faucibus, consectetur magna eu, feugiat augue. Maecenas in consequat lacus. Nulla placerat risus risus, mattis volutpat nisi accumsan at. Morbi imperdiet ultrices nunc sed consequat. Morbi blandit nisi nisi, ut aliquam orci posuere non. In hac habitasse platea dictumst. In eros risus, sodales quis luctus sed, sagittis quis mauris. Maecenas a felis enim. Etiam ac tempus justo.Pellentesque tincidunt posuere pretium. Integer eu augue sem. Pellentesque eget metus at nisi mattis elementum. Nunc erat sapien, eleifend quis est ut, pretium mattis nunc. Fusce vitae accumsan risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus bibendum risus dui, vitae fermentum magna imperdiet quis. Donec ornare ipsum quis nibh vestibulum, nec dignissim dolor egestas. Nunc rutrum condimentum egestas. Etiam porta congue lectus eu facilisis.</p>
                           ",
                SeoTitle = "Cool info", 
                MetaDescription = "Some really cool info", 
                MetaKeywords = "cool, info", 
                Visible = true, 
                ShowRating = true,
                Alias = "some-really-cool-info", 
                Published = DateTime.Now, 
                ViewCount = 0
            });
            context.SaveChanges();

            context.BlogEntryRatings.Add(new BlogEntryRating
            {
                BlogEntryId = 1, 
                UserId = 1, 
                Rating = 4.25
            });

            context.SaveChanges();

            context.BlogEntries.Add(new BlogEntry
            {
                Created = DateTime.Now,
                CategoryId = cts[1].Id,
                Header = "Fantastic News",
                HeaderUrl = "fantastic-news",
                ShortContent = @"<p><img alt='' src='/Uploads//MyFolder/blog/blog-thumb-1.jpg' style='width: 120px; height: 120px; float: left; border-width: 2px; border-style: solid; margin: 5px 10px;' />Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus dapibus nisl sit amet imperdiet. In hac habitasse platea dictumst. Suspendisse gravida ante nisi, sit amet volutpat augue aliquam non. Nulla sit amet velit faucibus, consectetur magna eu, feugiat augue. Maecenas in consequat lacus. Nulla placerat risus risus, mattis volutpat nisi accumsan at. Morbi imperdiet ultrices nunc sed consequat. Morbi blandit nisi nisi, ut aliquam orci posuere non. In hac habitasse platea dictumst. In eros risus, sodales quis luctus sed, sagittis quis mauris. Maecenas a felis enim. Etiam ac tempus justo.Pellentesque tincidunt posuere pretium. Integer eu augue sem. Pellentesque eget metus at nisi mattis elementum. Nunc erat sapien, eleifend quis est ut, pretium mattis nunc. Fusce vitae accumsan risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus bibendum risus dui, vitae fermentum magna imperdiet quis. Donec ornare ipsum quis nibh vestibulum, nec dignissim dolor egestas. Nunc rutrum condimentum egestas. Etiam porta congue lectus eu facilisis.</p>",
                Content = @"<p><img alt='' src='/Uploads//MyFolder/blog/blog1-big.jpg' style='width: 764px; height: 287px; border-width: 2px; border-style: solid;' /></p>
                            <p style='text-align: justify;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus dapibus nisl sit amet imperdiet. In hac habitasse platea dictumst. Suspendisse gravida ante nisi, sit amet volutpat augue aliquam non. Nulla sit amet velit faucibus, consectetur magna eu, feugiat augue. Maecenas in consequat lacus. Nulla placerat risus risus, mattis volutpat nisi accumsan at. Morbi imperdiet ultrices nunc sed consequat. Morbi blandit nisi nisi, ut aliquam orci posuere non. In hac habitasse platea dictumst. In eros risus, sodales quis luctus sed, sagittis quis mauris. Maecenas a felis enim. Etiam ac tempus justo.Pellentesque tincidunt posuere pretium. Integer eu augue sem. Pellentesque eget metus at nisi mattis elementum. Nunc erat sapien, eleifend quis est ut, pretium mattis nunc. Fusce vitae accumsan risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus bibendum risus dui, vitae fermentum magna imperdiet quis. Donec ornare ipsum quis nibh vestibulum, nec dignissim dolor egestas. Nunc rutrum condimentum egestas. Etiam porta congue lectus eu facilisis.</p>
                           ",
                SeoTitle = "Fantastic news",
                MetaDescription = "Fantastic news",
                MetaKeywords = "news, fantastic",
                Visible = true,
                ShowRating = true,
                Alias = "fantastic-news",
                Published = DateTime.Now,
                ViewCount = 0
            });
            context.SaveChanges();

            context.BlogEntryRatings.Add(new BlogEntryRating
            {
                BlogEntryId = 2,
                UserId = 1,
                Rating = 4.50
            });

            context.SaveChanges();

            context.BlogEntries.Add(new BlogEntry
            {
                Created = DateTime.Now,
                CategoryId = cts[2].Id,
                Header = "Public Notification",
                HeaderUrl = "public-notification",
                ShortContent = @"<p><img alt='' src='/Uploads//MyFolder/blog/blog-thumb-3.jpg' style='width: 120px; height: 119px; border-width: 2px; border-style: solid; margin: 5px 10px; float: left;' />Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus dapibus nisl sit amet imperdiet. In hac habitasse platea dictumst. Suspendisse gravida ante nisi, sit amet volutpat augue aliquam non. Nulla sit amet velit faucibus, consectetur magna eu, feugiat augue. Maecenas in consequat lacus. Nulla placerat risus risus, mattis volutpat nisi accumsan at. Morbi imperdiet ultrices nunc sed consequat. Morbi blandit nisi nisi, ut aliquam orci posuere non. In hac habitasse platea dictumst. In eros risus, sodales quis luctus sed, sagittis quis mauris. Maecenas a felis enim. Etiam ac tempus justo.Pellentesque tincidunt posuere pretium. Integer eu augue sem. Pellentesque eget metus at nisi mattis elementum. Nunc erat sapien, eleifend quis est ut, pretium mattis nunc. Fusce vitae accumsan risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus bibendum risus dui, vitae fermentum magna imperdiet quis. Donec ornare ipsum quis nibh vestibulum, nec dignissim dolor egestas. Nunc rutrum condimentum egestas. Etiam porta congue lectus eu facilisis.</p>
                            ",
                Content = @"<p><img alt='' src='/Uploads//MyFolder/blog/blog3-big.jpg' style='width: 764px; height: 287px; border-width: 2px; border-style: solid;' /></p>
                            <p style='text-align: justify;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus dapibus nisl sit amet imperdiet. In hac habitasse platea dictumst. Suspendisse gravida ante nisi, sit amet volutpat augue aliquam non. Nulla sit amet velit faucibus, consectetur magna eu, feugiat augue. Maecenas in consequat lacus. Nulla placerat risus risus, mattis volutpat nisi accumsan at. Morbi imperdiet ultrices nunc sed consequat. Morbi blandit nisi nisi, ut aliquam orci posuere non. In hac habitasse platea dictumst. In eros risus, sodales quis luctus sed, sagittis quis mauris. Maecenas a felis enim. Etiam ac tempus justo.Pellentesque tincidunt posuere pretium. Integer eu augue sem. Pellentesque eget metus at nisi mattis elementum. Nunc erat sapien, eleifend quis est ut, pretium mattis nunc. Fusce vitae accumsan risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus bibendum risus dui, vitae fermentum magna imperdiet quis. Donec ornare ipsum quis nibh vestibulum, nec dignissim dolor egestas. Nunc rutrum condimentum egestas. Etiam porta congue lectus eu facilisis.</p>
                            ",
                SeoTitle = "Public notification",
                MetaDescription = "Public notification",
                MetaKeywords = "public, notification",
                Visible = true,
                ShowRating = true,
                Alias = "public-notification",
                Published = DateTime.Now,
                ViewCount = 0
            });
            context.SaveChanges();

            context.BlogEntryRatings.Add(new BlogEntryRating
            {
                BlogEntryId = 3,
                UserId = 1,
                Rating = 4.75
            });

            context.SaveChanges();

            #endregion

            #region Comments

            var blg_comments = new List<BlogEntryComment>
            {
                new BlogEntryComment { BlogEntryId = 1, Comment = "Wow wow wow! Did know that... Thanks, I'll keep watching!", CreatedAt = DateTime.Today, Email="batman@batman.com", Name="Batman"},
                new BlogEntryComment { BlogEntryId = 2, Comment = "Great news, guys! Keep going. Sounds really fantastic.", CreatedAt=DateTime.Today, Email="superman@superman.com", Name="Superman" },
                new BlogEntryComment { BlogEntryId = 3, Comment = "Does any one heard of that, folks? Thanks for letting me know, it's right in time!",  CreatedAt=DateTime.Today, Email="spiderman@spiderman.com", Name="Spiderman" },
                new BlogEntryComment { BlogEntryId = 3, ParentId = 3, Comment = "Bam! I've heard of that, but there were no confirmation somewhere .... Thanks guys keep us notified!", CreatedAt=DateTime.Today, Email="ninja_t@ninja.com", Name="Ninja turtle" },
               
            };

            blg_comments.ForEach(x => context.BlogEntryComments.Add(x));
            context.SaveChanges();

            #endregion

            #region Tags

            var tag1 = new BlogEntryTag() { Name = "Tag1" , CreatedAt = DateTime.Now, BlogEntries = new List<BlogEntry>() };
            tag1.BlogEntries.Add(context.BlogEntries.ToList()[0]);
            tag1.BlogEntries.Add(context.BlogEntries.ToList()[1]);
            context.BlogEntryTags.Add(tag1);

            var tag2 = new BlogEntryTag() { Name = "Tag2", CreatedAt = DateTime.Now, BlogEntries = new List<BlogEntry>() };
            tag2.BlogEntries.Add(context.BlogEntries.ToList()[1]);
            tag2.BlogEntries.Add(context.BlogEntries.ToList()[2]);
            context.BlogEntryTags.Add(tag2);

            var tag3 = new BlogEntryTag() { Name = "Tag3", CreatedAt = DateTime.Now, BlogEntries = new List<BlogEntry>() };
            tag3.BlogEntries.Add(context.BlogEntries.ToList()[2]);
            tag3.BlogEntries.Add(context.BlogEntries.ToList()[0]);
            context.BlogEntryTags.Add(tag3);

            context.SaveChanges();

            #endregion

            base.Seed(context);
        }
    }
}